<?php require_once '../global.php';

function king_def(){
	global $king;
	$king->access('keywords');

$_cmd=array(
		'delete'=>$king->lang->get('system/common/del'),
	);

	$_js=array(
		"\$.kc_list(K[0],K[1],'manage.php?action=view&kid='+K[0])",
		"''+ishow('manage.php',K[0],K[2])+''",//显示

	);
	$s=$king->openList($_cmd,'',$_js,$king->db->pagelist('manage.php?pid=PID&rn=RN',$king->db->getRows_number('%s_title_pingluen','kid!=0')));




	$_sql="select kid,ktitle,nshow from %s_title_pingluen order by kid desc";
	if(!$res=$king->db->getRows($_sql,1)) $res=array();


	$s.="function ishow(url,id,is){var I1,ico;is?ico='n1':ico='n2';";
	$s.="I1='<a id=\"nshow_'+id+'\" class=\"k_ajax\" rel=\"{CMD:\'show\',value:'+ (1-is) +',ID:\'nshow_'+id+'\',list:'+id+',IS:2}\" >'+$.kc_icon(ico,(is?'".$king->lang->get('keywords/list/unshow')."':'".$king->lang->get('keywords/list/show')."'))+'</a>';return I1;};";
	$s.="ll('".$king->lang->get('keywords/list/title')."',
	    'manage',1);";



	foreach($res as $rs){
		$s.="ll({$rs['kid']},
		    '".addslashes(htmlspecialchars($rs['ktitle']))."',
		    ".$rs['nshow'].",
		    '".kc_formatdate($rs['ndate'])."',0);";
	}




	$s.=$king->closeList();

	list($left,$right)=inc_menu();

			
	$king->skin->output($king->lang->get('taobaoapi/title/center'),$left, $bs,$s);

}


/**
菜单调用
*/
function inc_menu(){
	global $king;
	$left=array(
		'edt'=>array(
			'href'=>'javascript:;',
			'ico'=>'c2',
			'title'=>'添加匹配模式',
			'rel'=>"{CMD:'edt',METHOD:'GET',URL:'./manage.php'}",
			'class'=>"k_ajax",
		),
		'2'=>array(
			'href'=>'pl.php',
			'ico'=>'p7',
			'title'=>'评论',
			),
		'3'=>array(
			'href'=>'manage.php',
			'ico'=>'p7',
			'title'=>'匹配模式',
			),

	);
	

	return array($left,array());
}



//删除留言
function king_ajax_delete(){
	global $king;
	$king->access('keywords_delete');
	$list=kc_getlist();
	$king->db->query("delete from %s_title_pingluen where kid in ($list)");
	kc_ajax('OK',"<p class=\"k_ok\">".$king->lang->get('system/ok/delete')."</p>",1);
}



//显示隐藏
function king_ajax_show(){
	global $king;
	$king->access('keywords_edt');
	$kid=kc_get('list',2,1);
	$value=kc_get('value',2,1);
	$king->db->query("update %s_title_pingluen set nshow=$value where kid=$kid;");
	$value ? $ico='n1':$ico='n2';
	kc_ajax('',
		kc_icon($ico,($value?$king->lang->get('taobaoapi/list/unshow'):$king->lang->get('taobaoapi/list/show'))),
		0,
		"$('#nshow_{$kid}').attr('rel','{CMD:\'show\',value:".(1-$value).",ID:\'nshow_{$kid}\',list:\'$kid\',IS:2}')");
}




function king_ajax_edt(){
			global $king;
			$king->access('portal_express');
				
				$title=kc_post('ktitle');	
				$data=$_POST;
				$_array=array(
				array('ktitle',0,'匹配模式'),
				);		
				$s.=kc_htm_hidden(array('but'=>'add'));//这个隐藏域				
				$s.=$king->htmForm('匹配模式','<textarea name="ktitle" class="k_in" style="width:400px;height:70px;" ></textarea>',$_array,null,"<tt></tt>");
				$but=kc_htm_a('提交','{URL:\'manage.php\',CMD:\'edt\'}');	
				$s.=$GLOBALS['ischeck'];

			if($data['but']=='add' && $GLOBALS['ischeck']){//有密码 并 账号验证成功的时候进行验证
				
		

					$a = explode("\n",$title);

	
		
						foreach($a as $key => $val){
															
									$k_array[$key]=array(
										'ktitle'=>$val,
										'nshow'=>'1',	
									);
									if(!$sds=$king->db->getRows_one("select ktitle from %s_title_pingluen where ktitle='".$val."'") && !empty($val)){
										$kid=$king->db->insert('%s_title_pingluen',$k_array[$key]);
									}
						}

						

					kc_ajax('OK',"<p class=\"k_ok\">添加成功</p>",1);
			}
		
			kc_ajax('匹配模式',$s,$but,'',570,200);

	}


?>